
////////////////////////////////////////////////////////////
//	File:		"AL_Task.cpp"
//	Author:		[AL] Anthony Lundquist
//	Created:	[AL] March 14, 2010
//	Purpose:	the base task class
////////////////////////////////////////////////////////////

#include "AL_Task.h"

/* Data Members */

/* Constructors */

AL_Task::AL_Task(int _nTaskType) : m_nType(_nTaskType), m_nNumDependencies(0)
{
}

/* Accessors */

/* Mutators */

/* Other Functions */
void AL_Task::DependensyFinished(AL_Task* _pTask)
{
	// decrease the amount of dependensies we have stored
	// TODO: Should we also remove items from the DependsOn vector?
	m_nNumDependencies--;
}

void AL_Task::SetDependensy(AL_Task* _pDependency,int _nTaskType)
{
	std::pair<AL_Task*,int> newDepend;
	newDepend.first  = _pDependency;
	newDepend.second = _nTaskType;

	m_vDependsOn.push_back(newDepend);
}

void AL_Task::RunTask(float _fDelta)
{
	typedef void (*TaskFunc)(float _fDelta);
	TaskFunc RunFunc = (TaskFunc)m_pTaskFunc;

	// run the task
	(*RunFunc)(_fDelta);
}

void AL_Task::FinishTask()
{
	// notify all that depend on us that we are done
	for(unsigned int i=0 ; i<m_vDependsOn.size() ; i++)
		m_vDependsOn[i].first->DependensyFinished(this);
}

bool AL_Task::CheckIfCanRun()
{
	// if we have 0 dependencies left than we can run
	return (m_nNumDependencies <= 0) ? true : false;
}

/* Destructor */

AL_Task::~AL_Task()
{
}

/* Protected Functions */

/* Private Functions */

